package com.admin.business.background.venusOaPrizepunApprovalset;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 员工奖惩审批设置表
 * @create: 2023-11-04 13:55:01
 **/
@Service("venusOaPrizepunApprovalsetService")
@Slf4j
public class VenusOaPrizepunApprovalsetService{

    @Resource
    VenusOaPrizepunApprovalsetDao venusOaPrizepunApprovalsetDao;

    /**
     * 添加员工奖惩审批设置表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - approvalset_count:审批级数(1.一级，2.二级，3.三级，4.四级)默认2.二级
     *                   - orgapproval_money:公司奖惩金额上限
     *                   - projectapproval_money:项目奖惩金额上限
     *                   - joint_one_per:被处罚人上一级领导连带处罚金额占比
     *                   - joint_two_per:被处罚人上两级领导连带处罚金额占比
     *                   - joint_three_per:被处罚人上三级领导连带处罚金额占比
     *                   - day:超过几天自动通过
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return addVenusOaPrizepunApprovalset(CDO cdoRequest) {
        venusOaPrizepunApprovalsetDao.addVenusOaPrizepunApprovalset(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新员工奖惩审批设置表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - org_id:公司id
     *                   - project_id:项目id
     *                   - approvalset_count:审批级数(1.一级，2.二级，3.三级，4.四级)默认2.二级
     *                   - orgapproval_money:公司奖惩金额上限
     *                   - projectapproval_money:项目奖惩金额上限
     *                   - joint_one_per:被处罚人上一级领导连带处罚金额占比
     *                   - joint_two_per:被处罚人上两级领导连带处罚金额占比
     *                   - joint_three_per:被处罚人上三级领导连带处罚金额占比
     *                   - day:超过几天自动通过
     *                   - update_time:更新时间
     *                   - begin_time:开始时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return updateVenusOaPrizepunApprovalsetById(CDO cdoRequest) {
        venusOaPrizepunApprovalsetDao.updateVenusOaPrizepunApprovalsetById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除员工奖惩审批设置表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return deleteVenusOaPrizepunApprovalsetById(CDO cdoRequest){
        int count = venusOaPrizepunApprovalsetDao.deleteVenusOaPrizepunApprovalsetById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除员工奖惩审批设置表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return deleteVenusOaPrizepunApprovalset(CDO cdoRequest) {
        int count = venusOaPrizepunApprovalsetDao.deleteVenusOaPrizepunApprovalset(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取员工奖惩审批设置表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return getVenusOaPrizepunApprovalsetById(CDO cdoRequest) {
        CDO cdoMapperResult = venusOaPrizepunApprovalsetDao.getVenusOaPrizepunApprovalsetById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取员工奖惩审批设置表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return getVenusOaPrizepunApprovalsetListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaPrizepunApprovalsetDao.getVenusOaPrizepunApprovalsetListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaPrizepunApprovalsetDao.getVenusOaPrizepunApprovalsetCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取员工奖惩审批设置表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-11-04 13:55:01
     */
    @OpenApi
    public Return getVenusOaPrizepunApprovalsetListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusOaPrizepunApprovalsetDao.getVenusOaPrizepunApprovalsetListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusOaPrizepunApprovalsetDao.getVenusOaPrizepunApprovalsetCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
